﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
using System.Windows.Data;

namespace Milkify.ComponentModel
{
    public class ConvertExtension : MarkupExtension
    {
        public object Value { get; set; }
        public IValueConverter Converter { get; set; }
        public object Parameter { get; set; }
        public Type TargetType { get; set; }

        public ConvertExtension()
        {
            TargetType = typeof(string);
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Converter == null)
                return Value;
            return Converter.Convert(Value, TargetType, Parameter, System.Globalization.CultureInfo.CurrentCulture);
        }
    }
}
